package com.rcloud.server.sealtalk.controller;


import com.github.binarywang.java.emoji.EmojiConverter;
import com.github.pagehelper.PageInfo;
import com.rcloud.server.sealtalk.constant.Constants;
import com.rcloud.server.sealtalk.constant.ErrorCode;
import com.rcloud.server.sealtalk.controller.param.UserAdvertisementParam;
import com.rcloud.server.sealtalk.domain.UserAdvertisement;
import com.rcloud.server.sealtalk.domain.Users;
import com.rcloud.server.sealtalk.exception.ServiceException;
import com.rcloud.server.sealtalk.model.response.APIResult;
import com.rcloud.server.sealtalk.model.response.APIResultWrap;
import com.rcloud.server.sealtalk.service.MiniWebSocketService;
import com.rcloud.server.sealtalk.service.UserAdvertisementService;
import com.rcloud.server.sealtalk.service.UsersService;
import com.rcloud.server.sealtalk.util.N3d;
import io.rong.messages.UserInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;


/**
 * 用户广告信息相关接口
 */
@Api(tags = "用户广告信息相关接口")
@Slf4j
@RestController
@RequestMapping("/user/advertisement")
@AllArgsConstructor
public class UserAdvertisementController extends BaseController {

    private UserAdvertisementService advertisementService;

    private UsersService usersService;

    @ApiOperation("广告信息发布的接口")
    @PostMapping("/submitAdvertisement")
    public APIResult<Object> submitAdvertisement(@RequestBody UserAdvertisementParam param) throws ServiceException {
        if (StringUtils.isEmpty(param.getTitle()) || StringUtils.isEmpty(param.getContent())) {
            throw new ServiceException(ErrorCode.WECHAT_PARAMS_NOT_EMPTY);
        }
        Integer userId = getCurrentUserId();
        // 查询当前登录用户信息
        Users loginUser = usersService.getByPrimaryKey(userId);
        if (loginUser.getAvailableTime() <= 0) {
            throw new ServiceException(ErrorCode.AVAILABLE_TIME_NOT_ENOUGH);
        }
        UserAdvertisement advertisement = UserAdvertisement.builder().build();
        // 进行emoji表情的转换
        EmojiConverter emojiConverter = EmojiConverter.getInstance();
        advertisement.setTitle(emojiConverter.toAlias(param.getTitle()));
        advertisement.setContent(emojiConverter.toAlias(param.getContent()));
        advertisement.setMobileLink(param.getMobileLink());
        Date date = new Date();
        advertisement.setCreateTime(date);
        advertisement.setUpdateTime(date);
        //原始图片
        if (param.getImageUrl() != null && !"".equals(param.getImageUrl())) {
            advertisement.setImageUrl(param.getImageUrl());
        }
        advertisement.setUserId(userId.toString());
        advertisement.setAccessType(param.getAccessType());
        advertisement.setIsShow(0);
        int i = advertisementService.saveSelective(advertisement);
        //发布成功那么 进行次数扣减
        if (i == 1) {
            try {
                UserInfo userInfo = new UserInfo(userId.toString(), loginUser.getNickname(), loginUser.getPortraitUri(), "");
                //todo 查询全部用户并进行消息通知
                advertisementService.sendNoticeMsg(userId, loginUser.getNickname(),
                        advertisement.getId().toString(),
                        Constants.CONTACT_OPERATION_ACCEPT_RESPONSE,
                        param.getTitle() == null ? "您有一条新的商机，请查收" : param.getTitle(),
                        param.getContent(),
                        param.getImageUrl(),
                        userInfo);
            } catch (Exception e) {
                log.error("进行消息通知出现错误1");
            }
            //更新用户的发布次数
            Users user = new Users();
            user.setId(userId);
            user.setAvailableTime(loginUser.getAvailableTime() - 1);
            usersService.updateByPrimaryKeySelective(user);
        }
        return APIResultWrap.ok("", "发布成功！");
    }


    /**
     * 广告信息编辑的接口
     */
    @ApiOperation("广告信息编辑的接口")
    @PostMapping("/updateAdvertisement/{advertisementId}")
    public APIResult<Object> updateAdvertisement(@PathVariable Integer advertisementId,
                                                 @RequestBody UserAdvertisementParam param) throws ServiceException {
        if (StringUtils.isEmpty(param.getTitle())
                && StringUtils.isEmpty(param.getContent())) {
            throw new ServiceException(ErrorCode.WECHAT_PARAMS_NOT_EMPTY);
        }
        Integer userId = getCurrentUserId();
        // 查询当前登录用户信息
        Users loginUser = usersService.getByPrimaryKey(userId);
        // 查询当前广告编辑信息
        UserAdvertisement advertisement1 = advertisementService.getByPrimaryKey(advertisementId);
        if (!userId.toString().equals(advertisement1.getUserId())) {
            throw new ServiceException(ErrorCode.CAT_NOT_EDIT_OTHER_INFO);
        }
        if (advertisement1.getEditNum() <= 0) {
            throw new ServiceException(ErrorCode.EDIT_TIME_NOT_ENOUGH);
        }
        UserAdvertisement advertisement = UserAdvertisement.builder().build();
        // 进行emoji表情的转换
        EmojiConverter emojiConverter = EmojiConverter.getInstance();
        advertisement.setId(advertisementId);
        advertisement.setTitle(emojiConverter.toAlias(param.getTitle()));
        advertisement.setContent(emojiConverter.toAlias(param.getContent()));
        advertisement.setUpdateTime(new Date());
        advertisement.setAccessType(param.getAccessType());
        advertisement.setMobileLink(param.getMobileLink());
        advertisement.setEditNum(advertisement1.getEditNum() - 1);
        //原始图片
        if (param.getImageUrl() != null && !"".equals(param.getImageUrl())) {
            advertisement.setImageUrl(param.getImageUrl());
        } else {
            advertisement.setImageUrl(null);
        }
        advertisement.setUserId(userId.toString());
        advertisement.setIsShow(0);
        int i = advertisementService.updateByPrimaryKeySelective(advertisement);
        //发布成功那么 进行次数扣减
        if (i == 1) {
            try {
                UserInfo userInfo = new UserInfo(userId.toString(), loginUser.getNickname(), loginUser.getPortraitUri(), "");
                //todo 查询全部用户并进行消息通知
                advertisementService.sendNoticeMsg(userId,
                        loginUser.getNickname(),
                        advertisementId.toString(),
                        Constants.CONTACT_OPERATION_ACCEPT_RESPONSE,
                        param.getTitle() == null ? "您有一条新的商机，请查收" : param.getTitle(),
                        param.getContent(),
                        param.getImageUrl(),
                        userInfo);
            } catch (Exception e) {
                log.error("进行消息通知出现错误2");
            }
        }
        return APIResultWrap.ok("", "编辑成功！");
    }


    /**
     * 根据关键字搜索广告发布信息
     */
    @GetMapping(value = "/searchAdvertisements")
    @ApiOperation(value = "根据关键字搜索广告发布信息", notes = "根据关键字搜索广告发布信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示数量", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "orderBy", value = "排序字段 1.时间 2.手机号查询次数 3.点击量", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "sort", value = "升序还是降序  desc降序  asc升序", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "keywords", value = "查询关键字", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "accessType", value = "进出货类型 1进货 2出货", required = false, dataType = "int", paramType = "query")
    })
    public APIResult<Object> searchAdvertisements(@RequestParam Integer pageNo,
                                                  @RequestParam Integer pageSize,
                                                  @RequestParam(defaultValue = "1") String orderBy,
                                                  @RequestParam(defaultValue = "desc") String sort,
                                                  @RequestParam String keywords,
                                                  @RequestParam(required = false) Integer accessType) throws ServiceException {
        Map<String, Object> resultMap = new HashMap<>();
        //增加通配符
        if (StringUtils.isNotBlank(keywords)) {
            keywords = "%" + keywords + "%";
        }
        Example example = new Example(UserAdvertisement.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("isShow", 1);
        //查询进货还是出货
        if (accessType != null) {
            criteria.andEqualTo("accessType", accessType);
        }
        //设置查询的条件
        if (keywords != null && !"".equals(keywords)) {
            criteria.andCondition("(title like '" + keywords + "' or content like '" + keywords + "')");
        }
        String orderStr = "";
        //排序
        if ("1".equals(orderBy)) {
            orderStr += "update_time";
            if ("desc".equals(sort)) {
                orderStr += " desc";
            } else {
                orderStr += " asc";
            }
        } else if ("2".equals(orderBy)) {
            orderStr += "query_mobile_num";
            if ("desc".equals(sort)) {
                orderStr += " desc";
            } else {
                orderStr += " asc";
            }
        } else if ("3".equals(orderBy)) {
            orderStr += "click_num";
            if ("desc".equals(sort)) {
                orderStr += " desc";
            } else {
                orderStr += " asc";
            }
        } else {
            orderStr += "update_time desc";
        }
        //注意：排序使用的是列名
        //"`click_num` desc, `query_mobile_num` desc, `update_time` desc"
        example.setOrderByClause(orderStr);
        //分页
        //条件查询使用的是属性名
        Map<String, Object> map = new HashMap<>();
        map.put("pageNo", pageNo);
        map.put("pageSize", pageSize);
        map.put("example", example);
        PageInfo<UserAdvertisement> userAdvertisementPageInfo = advertisementService.selectPageInfo(map);
        EmojiConverter emojiConverter = EmojiConverter.getInstance();
        //遍历放置用户信息
        for (UserAdvertisement advertisement : userAdvertisementPageInfo.getList()) {
            advertisement.setTitle(emojiConverter.toUnicode(advertisement.getTitle()));
            advertisement.setContent(emojiConverter.toUnicode(advertisement.getContent()));
            // 设置用户信息
            Users users = usersService.getByPrimaryKey(Integer.parseInt(advertisement.getUserId()));
            if (users == null) {
                userAdvertisementPageInfo.getList().remove(advertisement);
            } else {
                advertisement.setUserNickname(users.getNickname());
                advertisement.setUserAvatar(users.getPortraitUri());
                advertisement.setUserId(N3d.encode(Long.parseLong(advertisement.getUserId())));
            }
        }
        // 设置用户的返回数据
        resultMap.put("userAdvertisementPageInfo", userAdvertisementPageInfo);
        return APIResultWrap.ok(resultMap);
    }

    /**
     * 查询置顶广告列表
     */
    @GetMapping(value = "/queryTopAdvertisements")
    @ApiOperation(value = "查询置顶广告列表", notes = "查询置顶广告列表")
    public APIResult<Object> queryTopAdvertisements() throws ServiceException {
        Map<String, Object> resultMap = new HashMap<>();
        Example example = new Example(UserAdvertisement.class);
        Example.Criteria criteria = example.createCriteria();
        //设置查询的条件
        criteria.andEqualTo("isTop", 1);
        criteria.andEqualTo("isShow", 1);
        //注意：排序使用的是列名
        example.setOrderByClause("`seq` desc, `update_time` desc");
        //分页
        //条件查询使用的是属性名
        Map<String, Object> map = new HashMap<>();
        map.put("pageNo", 0);
        map.put("pageSize", 100);
        map.put("example", example);
        PageInfo<UserAdvertisement> userAdvertisementPageInfo = advertisementService.selectPageInfo(map);
        EmojiConverter emojiConverter = EmojiConverter.getInstance();
        //遍历放置用户信息
        for (UserAdvertisement advertisement : userAdvertisementPageInfo.getList()) {
            advertisement.setTitle(emojiConverter.toUnicode(advertisement.getTitle()));
            advertisement.setContent(emojiConverter.toUnicode(advertisement.getContent()));
            // 设置用户信息
            Users users = usersService.getByPrimaryKey(Integer.parseInt(advertisement.getUserId()));
            if (users == null) {
                userAdvertisementPageInfo.getList().remove(advertisement);
            } else {
                advertisement.setUserNickname(users.getNickname());
                advertisement.setUserAvatar(users.getPortraitUri());
                advertisement.setUserId(N3d.encode(Long.parseLong(advertisement.getUserId())));
            }
        }
        // 设置用户的返回数据
        resultMap.put("userAdvertisementPageInfo", userAdvertisementPageInfo);
        return APIResultWrap.ok(resultMap);
    }


    /**
     * 查看我的广告发布信息
     */
    @GetMapping(value = "/queryAdvertisements")
    @ApiOperation(value = "查看我的广告发布信息", notes = "查看我的广告发布信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示数量", required = true, dataType = "int", paramType = "query")
    })
    public APIResult<Object> queryAdvertisements(@RequestParam Integer pageNo,
                                                 @RequestParam Integer pageSize) throws ServiceException {
        Integer userId = getCurrentUserId();
        // 设置用户信息
        Users users = usersService.getByPrimaryKey(userId);
        Map<String, Object> resultMap = new HashMap<>();
        Example example = new Example(UserAdvertisement.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("userId", userId);
        //注意：排序使用的是列名
        example.setOrderByClause("update_time DESC");
        //分页
        //条件查询使用的是属性名
        Map<String, Object> map = new HashMap<>();
        map.put("pageNo", pageNo);
        map.put("pageSize", pageSize);
        map.put("example", example);
        PageInfo<UserAdvertisement> userAdvertisementPageInfo = advertisementService.selectPageInfo(map);
        EmojiConverter emojiConverter = EmojiConverter.getInstance();
        //遍历放置用户信息
        for (UserAdvertisement advertisement : userAdvertisementPageInfo.getList()) {
            advertisement.setTitle(emojiConverter.toUnicode(advertisement.getTitle()));
            advertisement.setContent(emojiConverter.toUnicode(advertisement.getContent()));
            advertisement.setUserId(N3d.encode(Long.parseLong(advertisement.getUserId())));
            advertisement.setUserNickname(users.getNickname());
            advertisement.setUserAvatar(users.getPortraitUri());
        }
        // 设置用户的返回数据
        resultMap.put("userAdvertisementPageInfo", userAdvertisementPageInfo);
        return APIResultWrap.ok(resultMap);
    }

    /**
     * 刷新我的广告信息
     */
    @GetMapping(value = "/refreshMyAdvertisement")
    @ApiOperation(value = "刷新我的广告信息", notes = "刷新我的广告信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "advertisementId", value = "广告信息ID", required = true, dataType = "int"),
    })
    public APIResult<Object> refreshMyAdvertisement(@RequestParam Integer advertisementId) throws ServiceException {
        Integer userId = getCurrentUserId();
        // 查询当前登录用户信息
        Users loginUser = usersService.getByPrimaryKey(userId);
        //判断信息是否存在
        UserAdvertisement byPrimaryKey = advertisementService.getByPrimaryKey(advertisementId);
        if (byPrimaryKey != null) {
            //判断是否是本人的广告信息
            if (!byPrimaryKey.getUserId().equals(userId.toString())) {
                throw new ServiceException(ErrorCode.CAN_NOT_REMOVE_OTHER_ADVERTISEMENT_INFO);
            }
            if (byPrimaryKey.getRefreshNum() <= 0) {
                throw new ServiceException(ErrorCode.REFRESH_TIME_NOT_ENOUGH);
            }
            //设置更新条件
            Example example = new Example(UserAdvertisement.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("id", byPrimaryKey.getId());
            criteria.andEqualTo("version", byPrimaryKey.getVersion());
            //执行刷新
            UserAdvertisement paramsAd = UserAdvertisement.builder().build();
            paramsAd.setVersion(byPrimaryKey.getVersion() + 1);
            paramsAd.setRefreshNum(byPrimaryKey.getRefreshNum() - 1);
            paramsAd.setUpdateTime(new Date());
            advertisementService.updateByExampleSelective(paramsAd, example);
            //判断是否 发送消息 ,不显示得不发送
            try {
                UserInfo userInfo = new UserInfo(userId.toString(), loginUser.getNickname(), loginUser.getPortraitUri(), "");
                // todo  需要全局通知用户 消息刷新成功
                advertisementService.sendNoticeMsg(userId, loginUser.getNickname(), advertisementId.toString(),
                        Constants.CONTACT_OPERATION_ACCEPT_RESPONSE,
                        byPrimaryKey.getTitle() == null ? "您有一条新的商机，请查收" : byPrimaryKey.getTitle(),
                        byPrimaryKey.getContent(), byPrimaryKey.getImageUrl(), userInfo);
            } catch (Exception e) {
                log.error("进行消息通知出现错误3");
            }
            return APIResultWrap.ok("刷新成功！");
        } else {
            throw new ServiceException(ErrorCode.NOT_QUERY_ADVERTISEMENT_INFO);
        }

    }


    /**
     * 删除我的广告信息
     */
    @GetMapping(value = "/removeMyAdvertisement")
    @ApiOperation(value = "删除我的广告信息", notes = "查看我的广告信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "advertisementId", value = "广告信息ID", required = true, dataType = "int"),
    })
    public APIResult<Object> removeMyAdvertisement(@RequestParam Integer advertisementId) throws ServiceException {
        Integer userId = getCurrentUserId();
        Users loginUser = usersService.getByPrimaryKey(userId);
        //判断信息是否存在
        UserAdvertisement byPrimaryKey = advertisementService.getByPrimaryKey(advertisementId);
        if (byPrimaryKey != null) {
            //判断是否是本人的广告信息
            if (!byPrimaryKey.getUserId().equals(userId.toString())) {
                throw new ServiceException(ErrorCode.CAN_NOT_REMOVE_OTHER_ADVERTISEMENT_INFO);
            }
        } else {
            throw new ServiceException(ErrorCode.NOT_QUERY_ADVERTISEMENT_INFO);
        }
        //执行删除操作
        int i = advertisementService.deleteByPrimaryKey(advertisementId);
        if (i == 1) {
            //更新用户的发布次数
            Users user = new Users();
            user.setId(userId);
            user.setAvailableTime(loginUser.getAvailableTime() + 1);
            usersService.updateByPrimaryKeySelective(user);
        }
        return APIResultWrap.ok("删除成功！");
    }

    /**
     * 查看广告信息
     */
    @GetMapping(value = "/queryAdvertisementDetailInfo")
    @ApiOperation(value = "查看广告信息详情", notes = "查看广告信息详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "advertisementId", value = "广告信息ID", required = true, dataType = "int"),
    })
    public APIResult<Object> queryAdvertisementDetailInfo(@RequestParam Integer advertisementId) throws ServiceException {
        Integer userId = getCurrentUserId();
        Users loginUser = usersService.getByPrimaryKey(userId);
        //判断信息是否存在
        UserAdvertisement advertisement = advertisementService.getByPrimaryKey(advertisementId);
        if (advertisement != null) {
            // 查询发布人的信息
            Users users = usersService.getByPrimaryKey(Integer.parseInt(advertisement.getUserId()));
            advertisement.setUserId(N3d.encode(Long.parseLong(advertisement.getUserId())));
            advertisement.setUserNickname(users.getNickname());
            advertisement.setUserAvatar(users.getPortraitUri());
            EmojiConverter emojiConverter = EmojiConverter.getInstance();
            advertisement.setTitle(emojiConverter.toUnicode(advertisement.getTitle()));
            advertisement.setContent(emojiConverter.toUnicode(advertisement.getContent()));
            //判断是否是本人的广告信息
            if (advertisement.getUserId().equals(userId.toString())) {

                return APIResultWrap.ok(advertisement);
            } else {
                //判断用户的认证状态
                /*if (loginUser.getIsMerchant() == 0) {
                    throw new ServiceException(ErrorCode.NOT_AUTH_QUERY_AD);
                }*/
                //设置更新条件
                Example example = new Example(UserAdvertisement.class);
                Example.Criteria criteria = example.createCriteria();
                criteria.andEqualTo("id", advertisement.getId());
                criteria.andEqualTo("version", advertisement.getVersion());
                //执行查看次数的更新
                UserAdvertisement paramsAd = UserAdvertisement.builder().build();
                paramsAd.setVersion(advertisement.getVersion() + 1);
                paramsAd.setClickNum(advertisement.getClickNum() + 1);
                advertisementService.updateByExampleSelective(paramsAd, example);
                return APIResultWrap.ok(advertisement);
            }
        } else {
            throw new ServiceException(ErrorCode.NOT_QUERY_ADVERTISEMENT_INFO);
        }
    }

    /**
     * 根据广告信息查看对方用户手机号
     */
    @GetMapping(value = "/queryMobileInfo")
    @ApiOperation(value = "根据广告信息查看对方用户手机号", notes = "根据广告信息查看对方用户手机号")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "advertisementId", value = "广告信息ID", required = true, dataType = "int"),
    })
    public APIResult<Object> queryMobileInfo(@RequestParam Integer advertisementId) throws ServiceException {
        Map<String, Object> resultMap = new HashMap<>();
        Integer userId = getCurrentUserId();
        Users loginUser = usersService.getByPrimaryKey(userId);
        //判断信息是否存在
        UserAdvertisement byPrimaryKey = advertisementService.getByPrimaryKey(advertisementId);
        if (byPrimaryKey != null) {
            //判断是否是本人的广告信息
            if (byPrimaryKey.getUserId().equals(userId.toString())) {
                resultMap.put("userId", N3d.encode(loginUser.getId()));
                if (byPrimaryKey.getMobileLink() != null) {
                    resultMap.put("phone", loginUser.getPhone());
                } else {
                    resultMap.put("phone", byPrimaryKey.getMobileLink());
                }
                return APIResultWrap.ok(resultMap);
            } else {
                //判断用户的认证状态
                if (loginUser.getIsMerchant() != 1) {
                    throw new ServiceException(ErrorCode.NOT_AUTH_QUERY_AD);
                }
                //设置更新条件
                Example example = new Example(UserAdvertisement.class);
                Example.Criteria criteria = example.createCriteria();
                criteria.andEqualTo("id", byPrimaryKey.getId());
                criteria.andEqualTo("version", byPrimaryKey.getVersion());
                //执行查看次数的更新
                UserAdvertisement paramsAd = UserAdvertisement.builder().build();
                paramsAd.setVersion(byPrimaryKey.getVersion() + 1);
                paramsAd.setQueryMobileNum(byPrimaryKey.getQueryMobileNum() + 1);
                advertisementService.updateByExampleSelective(paramsAd, example);
                // 查询发布人的账号信息
                Users users = usersService.getByPrimaryKey(Integer.parseInt(byPrimaryKey.getUserId()));
                resultMap.put("userId", N3d.encode(users.getId()));
                if (byPrimaryKey.getMobileLink() != null) {
                    resultMap.put("phone", byPrimaryKey.getMobileLink());
                } else {
                    resultMap.put("phone", users.getPhone());
                }
                return APIResultWrap.ok(resultMap);
            }
        } else {
            throw new ServiceException(ErrorCode.NOT_QUERY_ADVERTISEMENT_INFO);
        }
    }

    /**
     * 全局发送消息通知的接口
     */
    @PostMapping(value = "/noticeSystemMember")
    @ApiOperation(value = "全局发送消息通知的接口", notes = "全局发送消息通知的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pushNickname", value = "发送的用户昵称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "advertisementId", value = "广告信息ID", required = true, dataType = "String"),
    })
    public APIResult<Object> noticeSystemMember(@RequestParam String pushNickname,
                                                @RequestParam String advertisementId) throws ServiceException {
        //查询广告信息
        UserAdvertisement userAdvertisement = advertisementService.getByPrimaryKey(Integer.parseInt(advertisementId));
        if (userAdvertisement != null) {
            advertisementService.sendNoticeMsgForInterface(pushNickname, advertisementId);
        } else {
            throw new ServiceException(ErrorCode.NOT_QUERY_ADVERTISEMENT_INFO);
        }
        return APIResultWrap.ok();
    }


    /**
     * 随机获取广告信息进行发送的接口
     */
    @GetMapping(value = "/queryRandomAdvertisement")
    @ApiOperation(value = "随机获取广告信息进行发送的接口", notes = "随机获取广告信息进行发送的接口")
    public APIResult<Object> queryRandomAdvertisement() {
        UserAdvertisement userAdvertisement = advertisementService.queryRandomAdvertisement();
        return APIResultWrap.ok(userAdvertisement);
    }


}